import { Resolvers } from "../generated/graphql";
import sql from "../sql";
import * as busi from "../busi";
import * as util from "../util";
import { sys_app_info } from "../generated/sts_traffic_portal";

export const portal: Resolvers = {
  Query: {
    portal_app_list: async (_, args, ctx, info) => {
      busi.ensure_sso(ctx);
      const apps: sys_app_info[] = await sql`SELECT * FROM sys_app_info`;
      return apps.map(it => ({
        ...it,
        props: util.json_parse_safe(it.props!),
        open_citys: (it.open_citys || "").split(","),
      }));
    },
  },
};
